/*
 * @Description: 
 * @Author: iamsmiling
 * @Date: 2021-06-09 16:50:09
 * @LastEditTime: 2021-06-09 20:34:40
 */
import 'package:credit_business_circle/R/R.dart';
import 'package:credit_business_circle/components/filter_bar/filter_bar.dart';
import 'package:credit_business_circle/components/topic_card/topic_card.dart';
import 'package:credit_business_circle/domain/local/filter_option/settlement_mode_entity.dart';
import 'package:credit_business_circle/pages/topic/topic_list/fragment/settlement_filter_fragment.dart';
import 'package:credit_business_circle/pages/topic/topic_list/topic_list_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class TopicListPage extends GetView<TopicListController> {
  const TopicListPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext ctx) {
    return Scaffold(
      appBar: AppBar(
        title: Text("广告主"),
        elevation: 0,
        actions: [SizedBox.shrink()],
        leading: BackButton(),
      ),
      endDrawer: SettlementFilterFragment(
        options: controller.options,
        intialIndex: controller.currentSettlementIndex,
      ),
      endDrawerEnableOpenDragGesture: false,
      body: GetBuilder<TopicListController>(builder: (_) {
        return Container(
          margin: EdgeInsets.symmetric(horizontal: R.dimen.dp10),
          child: Column(
            children: [
              Container(
                margin: EdgeInsets.only(top: R.dimen.dp10),
                child: Column(
                  children: [FilterBar()],
                ),
              ),
              Container(
                margin: EdgeInsets.only(top: R.dimen.dp5),
                width: R.dimen.width,
                height: R.dimen.dp32,
                child: Stack(
                  children: [
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          margin: EdgeInsets.only(right: R.dimen.dp15),
                          child: Text(
                            "结算方式",
                            style: TextStyle(
                              fontSize: R.dimen.sp12,
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            margin: EdgeInsets.only(right: R.dimen.dp64),
                            child: ListView(
                              scrollDirection: Axis.horizontal,
                              shrinkWrap: true,
                              children: [
                                for (SettlementModeEntity item in _.options)
                                  Container(
                                    padding: EdgeInsets.symmetric(
                                        horizontal: R.dimen.dp6),
                                    margin: EdgeInsets.only(
                                        right: R.dimen.dp9,
                                        top: R.dimen.dp6,
                                        bottom: R.dimen.dp6),
                                    decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(R.dimen.sp3),
                                        color: _.currentSettlementIndex ==
                                                _.options.indexOf(item)
                                            ? R.color.ff33b18c
                                            : R.color.ffe8e8e8),
                                    alignment: Alignment.center,
                                    child: Text(
                                      item.label,
                                      style: TextStyle(
                                          fontSize: R.dimen.sp12,
                                          color: _.currentSettlementIndex ==
                                                  _.options.indexOf(item)
                                              ? R.color.ffffffff
                                              : R.color.ff666666),
                                    ),
                                  )
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                    Positioned(
                        right: 0,
                        child: Builder(builder: (context) {
                          return GestureDetector(
                            onTap: Scaffold.of(context).openEndDrawer,
                            child: Container(
                              padding: EdgeInsets.symmetric(
                                  horizontal: R.dimen.dp10,
                                  vertical: R.dimen.dp3),
                              margin: EdgeInsets.only(top: R.dimen.dp6),
                              decoration:
                                  BoxDecoration(color: R.color.fff5f5f5),
                              child: Row(
                                children: [
                                  Image.asset(R.image.funnel),
                                  Container(
                                    margin: EdgeInsets.only(left: R.dimen.dp10),
                                    child: Text(
                                      "筛选",
                                      style: TextStyle(
                                          fontSize: R.dimen.sp12,
                                          color: R.color.ff666666),
                                    ),
                                  )
                                ],
                              ),
                            ),
                          );
                        }))
                  ],
                ),
              ),
              Expanded(
                  child: ListView.builder(
                      shrinkWrap: true,
                      itemCount: _.topics.length,
                      itemBuilder: (BuildContext context, int i) {
                        return TopicCard(topic: _.topics[i]);
                      }))
            ],
          ),
        );
      }),
    );
  }
}
